package com.tangbuzhi.decorator;

/**
 * 装饰模式
 */
public class Decorator {
    public interface Sourceable {
        void method();
    }

    public static class Source implements Sourceable {
        @Override
        public void method() {
            System.out.println("this is original method");
        }
    }

    public static class SourceDecorator implements Sourceable {
        private Source source;

        public SourceDecorator(Source source) {
            this.source = source;
        }

        @Override
        public void method() {
            System.out.println("before decorator");
            source.method();
            System.out.println("after decorator");
        }
    }

    public static void main(String[] args) {
        Source source = new Source();
        Sourceable decorator = new SourceDecorator(source);
        decorator.method();
        /**
         before decorator
         this is original method
         after decorator
         */
    }
}
